package Client.Dropbox.Manager
import Client.Dropbox.SystemCommands.SystemListener

/**
 * Object for saving and managing the FileState
 */
object FileManager {
  
  var state = null.asInstanceOf[FileState]

  def root = state.root
  def user = state.user
  def client = state.client
  def myPort = state.getPort
  def serv = state.getServer
  def servPort = state.getServPort
  def tagger=state.getTagger
  
  /**
   * Initialize the FileManager by loading the latest FileState
   */
  def init {
    do {
      loadFS
    } while (state==null);
    SystemListener.setRoot(state.getRoot)
  }
  
  /**
   * Add a pair to the Folder hash map
   * @param path the folder path
   * @param id the folder id
   */
  def add(path:String, id:Long)=state.add(path, id)
  
  /**
   * Remove a pair from the hash map by the path
   * @param path the path to remove it by
   * @returns the matching id
   */
  def remove(path:String)=state.remove(path)
  
  /**
   * Remove a pair from the hash map by the id
   * @param id the id to remove it by
   * @returns the matching path
   */
  def remove(id:Long)=state.remove(id)
  
  /**
   * Get a folder id by its path
   * @param path the path
   * @return the matching id
   */
  def get(path:String):Long=state.get(path)
  
  /**
   * Get a folder path by its id
   * @param id the id
   * @returns the matching id
   */
  def get(id:Long):String=state.get(id)
  
  /**
   * Save the current file state to XML
   */
  def saveFS = FSLoader.save (state)
  
  /**
   * Load the file state from XML
   */
  def loadFS = {state=FSLoader.load}

}